<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  
  <title>redis | JAVA</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  <meta name="keywords" content="缓存">
  
  
  
  
  <meta name="description" content="redis基础知识 Key-Value数据库，NOSQL 存储，查询高效(Redis读的速度是110000次/秒,写的速度80000次/秒) 单线程，基于内存操作，CPU不是redis性能瓶颈，瓶颈是机器带宽和内存  存储数据结构  String    阅读数：只要点击该文章，可以使用incr key命令数字加1，完成数字记录 List    微信公众号的订阅推送，可以将文章的id记录在用户Lis">
<meta name="keywords" content="缓存">
<meta property="og:type" content="article">
<meta property="og:title" content="redis">
<meta property="og:url" content="https://jameslin23.gitee.io/2020/12/04/redis/index.html">
<meta property="og:site_name" content="JAVA">
<meta property="og:description" content="redis基础知识 Key-Value数据库，NOSQL 存储，查询高效(Redis读的速度是110000次/秒,写的速度80000次/秒) 单线程，基于内存操作，CPU不是redis性能瓶颈，瓶颈是机器带宽和内存  存储数据结构  String    阅读数：只要点击该文章，可以使用incr key命令数字加1，完成数字记录 List    微信公众号的订阅推送，可以将文章的id记录在用户Lis">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/04/redis/Users/Administrator.USER-20190627HM/AppData/Roaming/Typora/typora-user-images/image-20210123174406099.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/04/redis/Users/Administrator.USER-20190627HM/AppData/Roaming/Typora/typora-user-images/image-20210123174521246.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/04/redis/Users/Administrator.USER-20190627HM/AppData/Roaming/Typora/typora-user-images/image-20210123175053829.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/04/redis/Users/Administrator.USER-20190627HM/AppData/Roaming/Typora/typora-user-images/image-20210123175216737.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/04/redis/Users/Administrator.USER-20190627HM/AppData/Roaming/Typora/typora-user-images/image-20210123175456427.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/04/redis/Users/Administrator.USER-20190627HM/AppData/Roaming/Typora/typora-user-images/image-20210123175752709.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/04/redis/Users/Administrator.USER-20190627HM/AppData/Roaming/Typora/typora-user-images/image-20210123180144943.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/04/redis/Users/Administrator.USER-20190627HM/AppData/Roaming/Typora/typora-user-images/image-20210123180327197.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/04/redis/image-20201204150535800.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/04/redis/image-20201204150638693.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/04/redis/image-20201204150738688.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/04/redis/image-20201204162833185.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/04/redis/image-20201204162946548.png">
<meta property="og:updated_time" content="2021-02-23T09:04:05.089Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="redis">
<meta name="twitter:description" content="redis基础知识 Key-Value数据库，NOSQL 存储，查询高效(Redis读的速度是110000次/秒,写的速度80000次/秒) 单线程，基于内存操作，CPU不是redis性能瓶颈，瓶颈是机器带宽和内存  存储数据结构  String    阅读数：只要点击该文章，可以使用incr key命令数字加1，完成数字记录 List    微信公众号的订阅推送，可以将文章的id记录在用户Lis">
<meta name="twitter:image" content="https://jameslin23.gitee.io/2020/12/04/redis/Users/Administrator.USER-20190627HM/AppData/Roaming/Typora/typora-user-images/image-20210123174406099.png">
  
    <link rel="alternate" href="/atom.xml" title="JAVA" type="application/atom+xml">
  

  

  <link rel="icon" href="/css/images/mylogo.jpg">
  <link rel="apple-touch-icon" href="/css/images/mylogo.jpg">
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt; src:url("/css/fonts/FuturaPTBold.otf") format("woff");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt-light; src:url("/css/fonts/FuturaPTBook.otf") format("woff");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt-italic; src:url("/css/fonts/FuturaPTBookOblique.otf") format("woff");font-weight:400;font-style:italic;}
}

  </style>
  <link rel="stylesheet" href="/css/style.css">

  <script src="/js/jquery-3.1.1.min.js"></script>
  <script src="/js/bootstrap.js"></script>

  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="/css/bootstrap.css">

  
    <link rel="stylesheet" href="/css/dialog.css">
  

  

  
    <link rel="stylesheet" href="/css/header-post.css">
  

  
  
  
    <link rel="stylesheet" href="/css/vdonate.css">
  

</head>
</html>


  <body data-spy="scroll" data-target="#toc" data-offset="50">


  
  <div id="container">
    <div id="wrap">
      
        <header>

    <div id="allheader" class="navbar navbar-default navbar-static-top" role="navigation">
        <div class="navbar-inner">
          
          <div class="container"> 
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>

            
              <a class="brand" style="border-width: 0;">
                <p>JAVA</p>
              </a>
            
            
            <div class="navbar-collapse collapse">
              <ul class="hnav navbar-nav">
                
                  <li> <a class="main-nav-link" href="/">首页</a> </li>
                
                  <li> <a class="main-nav-link" href="/archives">归档</a> </li>
                
                  <li> <a class="main-nav-link" href="/categories">分类</a> </li>
                
                  <li> <a class="main-nav-link" href="/tags">标签</a> </li>
                
                  <li> <a class="main-nav-link" href="/about">关于</a> </li>
                
                  <li><div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder>
        <button type="submit" class="search-form-submit"></button>
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="请输入关键词...">
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(无标题)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>

</div></li>
            </ul></div>
          </div>
                
      </div>
    </div>

</header>



      
            
      <div id="content" class="outer">
        
          <section id="main" style="float:none;"><article id="post-redis" style="width: 75%; float:left;" class="article article-type-post" itemscope itemprop="blogPost">
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      redis
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2020/12/04/redis/" class="article-date">
	  <time datetime="2020-12-04T02:34:34.000Z" itemprop="datePublished">2020-12-04</time>
	</a>

      
    <a class="article-category-link" href="/categories/Nosql/">Nosql</a>

      
	<a class="article-views">
	<span id="busuanzi_container_page_pv">
		阅读量<span id="busuanzi_value_page_pv"></span>
	</span>
	</a>

      

    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="redis基础知识"><a href="#redis基础知识" class="headerlink" title="redis基础知识"></a>redis基础知识</h1><ul>
<li><strong>Key-Value数据库，NOSQL</strong></li>
<li><strong>存储，查询高效(Redis读的速度是110000次/秒,写的速度80000次/秒)</strong></li>
<li><strong>单线程，基于内存操作，CPU不是redis性能瓶颈，瓶颈是机器带宽和内存</strong></li>
</ul>
<h2 id="存储数据结构"><a href="#存储数据结构" class="headerlink" title="存储数据结构"></a>存储数据结构</h2><img src="/2020/12/04/redis/Users\Administrator.USER-20190627HM\AppData\Roaming\Typora\typora-user-images\image-20210123174406099.png" alt="image-20210123174406099" style="zoom:80%;">

<h3 id="String"><a href="#String" class="headerlink" title="String"></a>String</h3><img src="/2020/12/04/redis/Users\Administrator.USER-20190627HM\AppData\Roaming\Typora\typora-user-images\image-20210123174521246.png" alt="image-20210123174521246" style="zoom:80%;">

<img src="/2020/12/04/redis/Users\Administrator.USER-20190627HM\AppData\Roaming\Typora\typora-user-images\image-20210123175053829.png" alt="image-20210123175053829" style="zoom:80%;">

<p>阅读数：只要点击该文章，可以使用incr key命令数字加1，完成数字记录</p>
<h3 id="List"><a href="#List" class="headerlink" title="List"></a>List</h3><img src="/2020/12/04/redis/Users\Administrator.USER-20190627HM\AppData\Roaming\Typora\typora-user-images\image-20210123175216737.png" alt="image-20210123175216737" style="zoom:80%;">

<img src="/2020/12/04/redis/Users\Administrator.USER-20190627HM\AppData\Roaming\Typora\typora-user-images\image-20210123175456427.png" alt="image-20210123175456427" style="zoom: 25%;">

<p>微信公众号的订阅推送，可以将文章的id记录在用户List,从List遍历文章。</p>
<h3 id="Set"><a href="#Set" class="headerlink" title="Set"></a>Set</h3><img src="/2020/12/04/redis/Users\Administrator.USER-20190627HM\AppData\Roaming\Typora\typora-user-images\image-20210123175752709.png" alt="image-20210123175752709" style="zoom: 80%;">



<h3 id="Zset"><a href="#Zset" class="headerlink" title="Zset"></a>Zset</h3><p><strong>Sorted set</strong> 是排序的 <strong>Set</strong>，去重但可以排序，写进去的时候给一个分数，自动根据分数排序。</p>
<p>有序集合的使用场景与集合类似，但是set集合不是自动有序的，而<strong>Sorted set</strong>可以利用分数进行成员间的排序，而且是插入时就排序好。所以当你需要一个有序且不重复的集合列表时，就可以选择<strong>Sorted set</strong>数据结构作为选择方案。</p>
<ul>
<li><p><strong>排行榜</strong>：有序集合经典使用场景。例如视频网站需要对用户上传的视频做排行榜，榜单维护可能是多方面：按照时间、按照播放量、按照获得的赞数等。</p>
</li>
<li><p>用<strong>Sorted Sets</strong>来做带权重的队列，比如普通消息的score为1，重要消息的score为2，然后工作线程可以选择按score的倒序来获取工作任务。让重要的任务优先执行。</p>
<p>微博热搜榜，就是有个后面的热度值，前面就是名称</p>
</li>
</ul>
<img src="/2020/12/04/redis/Users\Administrator.USER-20190627HM\AppData\Roaming\Typora\typora-user-images\image-20210123180144943.png" alt="image-20210123180144943" style="zoom:80%;">

<h3 id="Hash"><a href="#Hash" class="headerlink" title="Hash"></a>Hash</h3><img src="/2020/12/04/redis/Users\Administrator.USER-20190627HM\AppData\Roaming\Typora\typora-user-images\image-20210123180327197.png" alt="image-20210123180327197" style="zoom:80%;">



<h3 id="BitMap"><a href="#BitMap" class="headerlink" title="BitMap"></a>BitMap</h3><blockquote>
<p>BitMap的基本原理就是用一个bit来标记某个元素对应的value,而key即是该元素。由于采用一个bit来存储一个数据，因此可以大大的节省空间。</p>
<p>我们通过一个具体例子来说明BitMap的原理。假设我们要对0-31内的3个元素(10,17,28)排序。我们就可以采用BitMap方法(假设这些元素没有重复)</p>
<p>如下图,要表示32个数，我们只需要32个bit(4Bytes)，首先我们开辟4Byte的空间,将这些空间的所有bit位都设置为0</p>
</blockquote>
<p><img src="https://jameslin23.gitee.io/2020/12/04/redis/image-20201204150535800.png" alt="image-20201204150535800"></p>
<p>然后，我们要添加(10, 17,28) 这三个数到 BitMap 中，需要的操作就是在相应的位置上将0置为1即可。如下图，比如现在要插入 10 这个元素，只需要将蓝色的那一位变为1即可。</p>
<p><img src="https://jameslin23.gitee.io/2020/12/04/redis/image-20201204150638693.png" alt="image-20201204150638693"></p>
<p>将这些数据插入后，假设我们想对数据进行排序或者检索数据是否存在，就可以依次遍历这个数据结构，碰到位为 1 的情况，就当这个数据存在。</p>
<p><strong>字符串映射</strong></p>
<blockquote>
<p>BitMap 也可以用来表述字符串类型的数据，但是需要有一层Hash映射，如下图，通过一层映射关系，可以表述字符串是否存在。</p>
</blockquote>
<p><img src="https://jameslin23.gitee.io/2020/12/04/redis/image-20201204150738688.png" alt="image-20201204150738688"></p>
<p>当然这种方式会有数据碰撞的问题，但可以通过 Bloom Filter 做一些优化。</p>
<p><strong>使用场景一：统计活跃用户</strong></p>
<blockquote>
<p>使用时间作为cacheKey，然后用户ID为offset(当用户很大时，需要优化)，如果当日活跃过就设置为1</p>
</blockquote>
<p><strong>使用场景二：户在线状态</strong></p>
<blockquote>
<p>只需要一个key，然后用户ID为offset(当用户很大时，需要优化)，如果在线就设置为1，不在线就设置为0</p>
</blockquote>
<p><strong>使用场景三 : 用户签到</strong></p>
<blockquote>
<p>用户ID作为key，签到的天数offest</p>
</blockquote>
<h3 id="Hyperloglog"><a href="#Hyperloglog" class="headerlink" title="Hyperloglog"></a>Hyperloglog</h3><p> <a href="https://mp.weixin.qq.com/s/9dtGe3d_mbbxW5FpVPDNow" target="_blank" rel="noopener">https://mp.weixin.qq.com/s/9dtGe3d_mbbxW5FpVPDNow</a></p>
<p>###　Geospatial</p>
<h1 id="redis持久化"><a href="#redis持久化" class="headerlink" title="redis持久化"></a>redis持久化</h1><p><strong>SAVE  保存是阻塞主进程，客户端无法连接redis，等SAVE完成后，主进程才开始工作，客户端可以连接</strong></p>
<p><strong>BGSAVE  是fork一个save的子进程，在执行save过程中，不影响主进程，客户端可以正常链接redis，等子进程fork执行save完成后，通知主进程，子进程关闭。很明显BGSAVE</strong></p>
<h2 id="RDB"><a href="#RDB" class="headerlink" title="RDB"></a>RDB</h2><blockquote>
<p>快照方式，每隔一段时间对内存数据做一次快照然后存储到硬盘中</p>
</blockquote>
<p><strong>RDB可以通过在配置文件中配置时间或者改动键的个数来定义快照条件，编辑配置文件redis.conf</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># 默认配置</span><br><span class="line">save 900 1    #15分钟之内至少有一个键被更改则进行快照</span><br><span class="line">save 300 10   #5分钟之内至少有10个键被更改则进行快照 </span><br><span class="line">save 60 10000 #1分钟之内至少有1000个键被更改则进行快照</span><br></pre></td></tr></table></figure>

<p>RDB持久化到磁盘文件默认路径是当前安装目录，文件名为dump.rdb，你可以通过配置文件dir和dbfilename来指定文件目录和文件名称，rdb文件还可以进行压缩,你可以通过配置rdbcompression参数进行压缩</p>
<p><img src="https://jameslin23.gitee.io/2020/12/04/redis/image-20201204162833185.png" alt="image-20201204162833185"></p>
<p><strong>执行流程</strong></p>
<blockquote>
<p>（1）redis根据配置自己尝试去生成rdb快照文件</p>
<p>（2）fork一个子进程出来</p>
<p>（3）子进程尝试将数据dump到临时的rdb快照文件中</p>
<p>（4）完成rdb快照文件的生成之后，就替换之前的旧的快照文件</p>
</blockquote>
<p><strong>存在问题</strong></p>
<blockquote>
<p>当还没进行sava，触发存储快照时，服务器宕机，会丢失上次保存快照-到宕机时这段时间的数据。</p>
</blockquote>
<h2 id="AOF"><a href="#AOF" class="headerlink" title="AOF"></a>AOF</h2><blockquote>
<p>记录客户端对服务器的每一个写操作命令,并将这些写操作以Redis协议追加保存到.aof文件,在redis服务器重启时,在redis服务器重启时，会加载并运行aof文件命令，已达到恢复数据的目的。</p>
</blockquote>
<p><img src="https://jameslin23.gitee.io/2020/12/04/redis/image-20201204162946548.png" alt="image-20201204162946548"></p>
<p><strong>开启AOF持久化方式</strong></p>
<p>Redis默认不开启AOF持久化方式，我们可以在配置文件中开启并进行更加详细的配置，如下面的redis.conf文件：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"># 开启aof机制</span><br><span class="line">appendonly yes</span><br><span class="line"></span><br><span class="line"># aof文件名</span><br><span class="line">appendfilename &quot;appendonly.aof&quot;</span><br><span class="line"></span><br><span class="line"># 写入策略,always表示每个写操作都保存到aof文件中,也可以是everysec或no</span><br><span class="line">appendfsync always</span><br><span class="line"></span><br><span class="line"># 默认不重写aof文件</span><br><span class="line">no-appendfsync-on-rewrite no</span><br><span class="line"></span><br><span class="line"># 保存目录</span><br><span class="line">dir ~/redis/</span><br></pre></td></tr></table></figure>

<p><strong>执行方式</strong></p>
<ul>
<li><p><strong>always</strong>: Redis的每条写命令都写入到系统缓冲区，然后每条写命令都使用fsync“写入”硬盘。</p>
<blockquote>
<p>客户端的每一个写操作都保存到aof文件当，这种策略很安全，但是每个写请注都有IO操作，所以也很慢。</p>
</blockquote>
</li>
<li><p><strong>everysec</strong>: 过程与always相同，只是fsync的频率为1秒钟一次。这个是Redis默认配置，如果系统宕机，会丢失一秒左右的数据</p>
<blockquote>
<p>appendfsync的默认写入策略，每秒写入一次aof文件，因此，最多可能会丢失1s的数据。</p>
</blockquote>
</li>
<li><p><strong>no</strong>: 由操作系统决定什么时候从系统缓冲区刷新到硬盘。</p>
<blockquote>
<p>Redis服务器不负责写入aof，而是交由操作系统来处理什么时候写入aof文件。更快，但也是最不安全的选择，不推荐使用。</p>
</blockquote>
</li>
</ul>
<p><strong>AOF文件重写</strong></p>
<blockquote>
<p>AOF将客户端的每一个写操作都追加到aof文件末尾，比如对一个key多次执行incr命令，这时候，aof保存每一次命令到aof文件中，aof文件会变得非常大。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">incr num <span class="number">1</span></span><br><span class="line">incr num <span class="number">2</span></span><br><span class="line">incr num <span class="number">3</span></span><br><span class="line">...</span><br><span class="line">incr num <span class="number">100000</span></span><br></pre></td></tr></table></figure>

<p>aof文件太大，加载aof文件恢复数据时，就会非常慢，为了解决这个问题，Redis支持aof文件重写，通过重写aof，可以生成一个恢复当前数据的最少命令集，比如上面的例子中那么多条命令，可以重写为:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">set num 100000</span><br></pre></td></tr></table></figure>

<p><strong>注意：通过在redis.conf配置文件中的选项no-appendfsync-on-rewrite可以设置是否开启重写，这种方式会在每次fsync时都重写，影响服务器性以，因此默认值为no，不推荐使用。</strong></p>
<p><strong>AOF文件损坏</strong></p>
<blockquote>
<p>在写入aof日志文件时，如果redis服务器宕机,则aof日志文件会出格式错误,在重启redis服务器时,redis服务器会拒绝载入这个aof文件，可以通过以下步骤修复aof并恢复数据</p>
<p>使用redis-check-aof命令修复aof文件，该命令格式如下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&gt; redis-check-aof -fix file.aof</span><br><span class="line">&gt;</span><br></pre></td></tr></table></figure>
</blockquote>
<p><strong>AOF的优点</strong></p>
<p>AOF只是追加日志文件，因此对服务器性能影响较小，速度比RDB要快，消耗的内存较小</p>
<p><strong>AOF的缺点</strong></p>
<ul>
<li>AOF方式生成的日志文件太大，即使通过AFO重写，文件体积仍然很大。</li>
<li>恢复数据的速度比RDB</li>
</ul>
<h2 id="RDB-VS-AOF"><a href="#RDB-VS-AOF" class="headerlink" title="RDB VS AOF"></a>RDB VS AOF</h2><table>
<thead>
<tr>
<th></th>
<th>RDB</th>
<th>AOF</th>
</tr>
</thead>
<tbody><tr>
<td>启动优先级</td>
<td>低</td>
<td>高</td>
</tr>
<tr>
<td>体积</td>
<td>小</td>
<td>大</td>
</tr>
<tr>
<td>恢复速度</td>
<td>快</td>
<td>慢</td>
</tr>
<tr>
<td>数据安全性</td>
<td>丢数据</td>
<td>根据策略</td>
</tr>
</tbody></table>
<h1 id="小总结"><a href="#小总结" class="headerlink" title="小总结"></a>小总结</h1><ul>
<li><strong>简单概述redis基础，8大数据结构，及bitmap原理，运用场景</strong></li>
<li><strong>redis两大持久化机制,RDB原理，AOF原理及各种优缺点</strong></li>
</ul>

      
    </div>
    <footer class="article-footer">
      
        <div id="donation_div"></div>

<script src="/js/vdonate.js"></script>
<script>
var a = new Donate({
  title: '如果觉得我的文章对您有用，请随意打赏。您的支持将鼓励我继续创作!', // 可选参数，打赏标题
  btnText: '打赏支持', // 可选参数，打赏按钮文字
  el: document.getElementById('donation_div'),
  wechatImage: 'https://raw.githubusercontent.com/iTimeTraveler/iTimeTraveler.github.io/site/source/about/donate/images/WeChanQR.png',
  alipayImage: 'https://raw.githubusercontent.com/iTimeTraveler/iTimeTraveler.github.io/site/source/about/donate/images/AliPayQR.jpg'
});
</script>
      
      
      <div>
        <ul class="post-copyright">
          <li class="post-copyright-author">
          <strong>本文作者:  </strong>LeBron Tao
          </li>
          <li class="post-copyright-link">
          <strong>本文链接:  </strong>
          <a href="/2020/12/04/redis/" target="_blank" title="redis">https://jameslin23.gitee.io/2020/12/04/redis/</a>
          </li>
          <li class="post-copyright-license">
            <strong>版权声明:   </strong>
            本博客所有文章除特别声明外，均采用 <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">CC BY-NC-ND 4.0</a>
            许可协议。转载请注明出处
          </li>
         
        </ul>
<div>
</div></div>
      
      
        
	<div id="comment">
		<!-- 来必力City版安装代码 -->
		<div id="lv-container" data-id="city" data-uid="MTAyMC8yOTQ4MS82MDQ5">
		<script type="text/javascript">
		   (function(d, s) {
		       var j, e = d.getElementsByTagName(s)[0];

		       if (typeof LivereTower === 'function') { return; }

		       j = d.createElement(s);
		       j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
		       j.async = true;

		       e.parentNode.insertBefore(j, e);
		   })(document, 'script');
		</script>
		<noscript>为正常使用来必力评论功能请激活JavaScript</noscript>
		</div>
		<!-- City版安装代码已完成 -->
	</div>



      
      
        
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/缓存/">缓存</a></li></ul>

      

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2020/12/04/RocketMQ单机模式/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">上一篇</strong>
      <div class="article-nav-title">
        
          RocketMQ单机模式
        
      </div>
    </a>
  
  
    <a href="/2020/12/01/ngnix/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">下一篇</strong>
      <div class="article-nav-title">Nginx</div>
    </a>
  
</nav>

  
</article>

<!-- Table of Contents -->

  <aside id="toc-sidebar">
    <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录</strong>
    
        <ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#redis基础知识"><span class="nav-number">1.</span> <span class="nav-text">redis基础知识</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#存储数据结构"><span class="nav-number">1.1.</span> <span class="nav-text">存储数据结构</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#String"><span class="nav-number">1.1.1.</span> <span class="nav-text">String</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#List"><span class="nav-number">1.1.2.</span> <span class="nav-text">List</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Set"><span class="nav-number">1.1.3.</span> <span class="nav-text">Set</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Zset"><span class="nav-number">1.1.4.</span> <span class="nav-text">Zset</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Hash"><span class="nav-number">1.1.5.</span> <span class="nav-text">Hash</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#BitMap"><span class="nav-number">1.1.6.</span> <span class="nav-text">BitMap</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Hyperloglog"><span class="nav-number">1.1.7.</span> <span class="nav-text">Hyperloglog</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#redis持久化"><span class="nav-number">2.</span> <span class="nav-text">redis持久化</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#RDB"><span class="nav-number">2.1.</span> <span class="nav-text">RDB</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#AOF"><span class="nav-number">2.2.</span> <span class="nav-text">AOF</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#RDB-VS-AOF"><span class="nav-number">2.3.</span> <span class="nav-text">RDB VS AOF</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#小总结"><span class="nav-number">3.</span> <span class="nav-text">小总结</span></a></li></ol>
    
    </div>
  </aside>

</section>
        
      </div>
      
      <footer id="footer">
  

  <div class="container">
      	<div class="row">
	      <p> Powered by <a href="http://hexo.io/" target="_blank">Hexo</a> and <a href="https://github.com/iTimeTraveler/hexo-theme-hiker" target="_blank">Hexo-theme-hiker</a> </p>
	      <p id="copyRightEn">Copyright &copy; 2013 - 2021 JAVA All Rights Reserved.</p>
	      
	      
    		<p class="busuanzi_uv">
				访客数 : <span id="busuanzi_value_site_uv"></span> |  
				访问量 : <span id="busuanzi_value_site_pv"></span>
		    </p>
  		   
		</div>

		
  </div>
</footer>


<!-- min height -->

<script>
    var wrapdiv = document.getElementById("wrap");
    var contentdiv = document.getElementById("content");
    var allheader = document.getElementById("allheader");

    wrapdiv.style.minHeight = document.body.offsetHeight + "px";
    if (allheader != null) {
      contentdiv.style.minHeight = document.body.offsetHeight - allheader.offsetHeight - document.getElementById("footer").offsetHeight + "px";
    } else {
      contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("footer").offsetHeight + "px";
    }
</script>
    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/categories" class="mobile-nav-link">Categories</a>
  
    <a href="/tags" class="mobile-nav-link">Tags</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav> -->
    

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/scripts.js"></script>




  <script src="/js/dialog.js"></script>








	<div style="display: none;">
    <script src="https://s95.cnzz.com/z_stat.php?id=1260716016&web_id=1260716016" language="JavaScript"></script>
  </div>



	<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js">
	</script>






  </div>

  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title" id="myModalLabel">设置</h2>
      </div>
      <hr style="margin-top:0px; margin-bottom:0px; width:80%; border-top: 3px solid #000;">
      <hr style="margin-top:2px; margin-bottom:0px; width:80%; border-top: 1px solid #000;">


      <div class="modal-body">
          <div style="margin:6px;">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" onclick="javascript:setFontSize();" aria-expanded="true" aria-controls="collapseOne">
              正文字号大小
            </a>
          </div>
          <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
          <div class="panel-body">
            您已调整页面字体大小
          </div>
        </div>
      


          <div style="margin:6px;">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" onclick="javascript:setBackground();" aria-expanded="true" aria-controls="collapseTwo">
              夜间护眼模式
            </a>
        </div>
          <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
          <div class="panel-body">
            夜间模式已经开启，再次单击按钮即可关闭 
          </div>
        </div>

        <div>
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="true" aria-controls="collapseThree">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;关 于&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
        </div>
         <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
          <div class="panel-body">
            JAVA
          </div>
          <div class="panel-body">
            Copyright © 2021 LeBron Tao All Rights Reserved.
          </div>
        </div>
      </div>


      <hr style="margin-top:0px; margin-bottom:0px; width:80%; border-top: 1px solid #000;">
      <hr style="margin-top:2px; margin-bottom:0px; width:80%; border-top: 3px solid #000;">
      <div class="modal-footer">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
      </div>
    </div>
  </div>
</div>
  
  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/js/totop.js?v=1.0.0" async=""></script>
  
    <a id="menu-switch"><i class="fa fa-bars fa-lg"></i></a>
  
</body>
</html>